package com.smartview.jboss.spring.aop;

import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.sql.SQLException;
import java.sql.*;

import javax.servlet.ServletException;

import org.apache.log4j.Logger;
import org.springframework.aop.ThrowsAdvice;

public class ThrowCatchInterceptor implements ThrowsAdvice {
	
	public void afterThrowing(RemoteException ex) throws Throwable {
		Logger.getRootLogger().error("catch exception!", ex);
	}
	
	public void afterThrowing(Method m,	Object[] args, Object target, ServletException ex) {
		Logger.getRootLogger().error("catch servlet exception!\n method : "+
				m.toString() + "\n class : " + target.getClass().getName()
				, ex);
	}
	
	public void afterThrowing(Method m, Object[] args, Object target, SQLException ex ) {
		Logger.getRootLogger().info("catch SQL exception!\n method : "+
				m.toString() + "\n class : " + target.getClass().getName()
				+ "\n ErrorCode : " + ex.getErrorCode()
				+ "\n Localizedmessage : " + ex.getLocalizedMessage()
				+ "\n Message : " + ex.getMessage()
				+ "\n SQLState : " + ex.getSQLState() );
	}
	
}
